import React, { Component } from "react";
import { withRouter } from "react-router-dom";

class Header extends Component {
    forward = () => {
        this.props.history.goForward();
    };

    back = () => {
        this.props.history.goBack();
    };

    render() {
        return (
            <div className="page-header">
                <h2>React Router Demo</h2>
                <button onClick={this.back}>后退</button>
                <button onClick={this.forward}>前进</button>
            </div>
        );
    }
}

/**
 * withRouter() 函数用于在一般组件中引入路由组件特有的props：history, location 和 match
 * 这个函数返回一个新组件
 */
export default withRouter(Header);
